package com.lagou.edu.service.impl;

import com.lagou.edu.dao.AccountDao;
import com.lagou.edu.pojo.Account;
import com.lagou.edu.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

@Service
@Transactional
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountDao accountDao;

    @Override
    public List<Account> queryAccountList() throws Exception {
        return accountDao.findAll();
    }

    @Override
    public Account hasAccount(Account account) {
        Optional<Account> one = this.accountDao.findOne(Example.of(account));
        if (one.isPresent()) {
            return one.get();
        }
        return null;
    }
}
